package algorithm.leetcode.I1to100;

/**
 * 贪心法
 */

public class Q55 {

    public boolean canJump(int[] nums) {
        int maxCanJump = 0;

        for (int i = 0; i < nums.length; i++) {
            // 第i个位置是可达的,更新最大可达位置
            if (maxCanJump >= i && maxCanJump < nums.length-1) {
                maxCanJump = Math.max(i + nums[i], maxCanJump);
            }

            else if (maxCanJump >= nums.length-1) return true;
        }
        return false;
    }

    public static void main(String[] args) {
        Q55 q55 = new Q55();
        System.out.println(q55.canJump(new int[]{2, 3, 1, 1, 4}));
    }

}
